import redis
from flask import Flask
from flask_cors import CORS
from flask_httpauth import HTTPTokenAuth


from app.db_base import db
from config import config

auth = HTTPTokenAuth('Operations')


def create_app(config_name):
    app = Flask(__name__)
    app.config.from_object(config[config_name])

    db.init_app(app)

    CORS(app, supports_crendentials=True)



    app.redis_store = redis.StrictRedis(host=app.config.get('REDIS_HOST'),
                                        port=app.config.get('REDIS_PORT'),
                                        db=4,
                                        decode_responses=True,
                                        charset='UTF-8',
                                        encoding='UTF-8')

    from .api_v1 import api
    app.register_blueprint(api, url_prefix='/api/v1')


    return app
